﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CrossBasket.cs" company="">
//   
// </copyright>
// <summary>
//   The cross basket.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System.Linq;
using Systemathics.FrameWork;
using Systemathics.Indicators;

namespace Systemathics.Automates
{
    [Pattern("Systemathics.Automates.MegaTrend.dll", "1.0")]
    [SetBars(BarType.Seconds, 30)]
    public sealed class Spread : Strategy
    {
        private OrderExtension ext = new OrderExtension() { Tif = TimeInForce.GoodTillCancel };
        private SystemathicsSound s = new SystemathicsSound();
        private SuperTrend st;

        public override void OnStart()
        {
            st = new SuperTrend(Instruments.First().Value,BarType.Seconds, 50, 10 , 3);
            Draw(Instruments.First().Value, Data.Quote, Axis.Primary, Axis.Primary);

            base.OnStart();
        }


        public override void OnBarClose(Bar bar)
        {
            if(st.DownBand != 0)
            {
                Instruments[bar.Id].CustomValue1 = st.UpBand;
                Instruments[bar.Id].CustomValue2 = st.DownBand;
            }            
        }
        public override void OnOrder(Order o)
        {
            switch (o.Status)
            {
                case OrderStatus.ACK:
                    //s.ACK();
                    break;
                case OrderStatus.ACK_CANCEL:
                    s.ACK_CANCEL();
                    break;
                case OrderStatus.ACK_MODIFY:
                    s.ACK_MODIFY();
                    break;
                case OrderStatus.FILLED:
                    // s.FILLED();   
                    break;
                case OrderStatus.PARTIALLY_FILLED:
                    //s.PARTIALLY_FILLED();
                    break;
                case OrderStatus.REJECT:
                    s.REJECT();
                    break;
                case OrderStatus.REJECT_CANCEL:
                    if (o.CancelRejectionNumber <= 1)
                        Instruments[o.InstrumentId].ReSend(o.Id);
                    // s.REJECT_CANCEL();
                    break;
                case OrderStatus.REJECT_MODIFY:
                    //s.REJECT_MODIFY();

                    // Make something
                    break;
            }
        }
        public override void OnMoneyManagement(MoneyManagement mm)
        {
            switch (mm.Reason)
            {
                case CashManagementTrigger.MaxBiasTriggered:
                    break;
                case CashManagementTrigger.MarginRequirementTriggered:
                    break;
                case CashManagementTrigger.MaxDrawDownTriggered:
                    break;
                case CashManagementTrigger.CashEquityNegative:
                    Log("Strategy Paused -------> CashEquityNegative :" + mm.Amount);
                    isPaused = true;
                    break;
            }
        }
        public override void OnTradeSeries(TradeSeries series)
        {
        }
        public override void OnQuoteSeries(QuoteSeries series)
        {
        }
        public override void OnBarSeries(BarSeries series)
        {
        }
        public override void OnBuild()
        {
            base.OnBuild();
        }
        public override void OnStop()
        {
            base.OnStop();
        }
    }
}